//package com.luanye.enjoy.flowable.extend;
//
//import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
//import lombok.extern.slf4j.Slf4j;
//import org.flowable.common.engine.impl.AbstractEngineConfiguration;
//import org.flowable.common.engine.impl.EngineConfigurator;
//import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
//import javax.sql.DataSource;
//import java.util.concurrent.atomic.AtomicBoolean;
//
//@Slf4j
//public class ChangeDataSourceEngineConfigurator implements EngineConfigurator {
//
//    private static AtomicBoolean initialized = new AtomicBoolean();
//
//    @Override
//    public void beforeInit(AbstractEngineConfiguration abstractEngineConfiguration) {
//        if (initialized.compareAndSet(false, true)){
//            //切换数据源
//            DataSource dataSource = abstractEngineConfiguration.getDataSource();
//            if (dataSource instanceof TransactionAwareDataSourceProxy){
//                dataSource = ((TransactionAwareDataSourceProxy)dataSource).getTargetDataSource();
//            }
//            if (dataSource instanceof DynamicRoutingDataSource){
//                dataSource = ((DynamicRoutingDataSource) dataSource).getDataSource("workflow");
//            }
//            abstractEngineConfiguration.setDataSource(dataSource);
//        }
//    }
//
//    @Override
//    public void configure(AbstractEngineConfiguration abstractEngineConfiguration) {
//
//    }
//
//    @Override
//    public int getPriority() {
//        return 0;
//    }
//}
